package com.paw.ruoyi.admin.controller.monitor;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.paw.ruoyi.admin.common.annotion.OperatorLog;
import com.paw.ruoyi.admin.common.annotion.RequiresPermissions;
import com.paw.ruoyi.admin.common.annotion.SkipLogParam;
import com.paw.ruoyi.admin.common.annotion.SkipResponseLog;
import com.paw.ruoyi.admin.common.constant.BusinessType;
import com.paw.ruoyi.admin.common.AjaxResult;
import com.paw.ruoyi.admin.common.TableDataInfo;
import com.paw.ruoyi.admin.controller.BaseController;
import com.paw.ruoyi.admin.domain.SysLogininfor;
import com.paw.ruoyi.admin.service.ISysLogininforService;
import com.paw.ruoyi.admin.utils.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 系统访问记录
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/api/monitor/logininfor")
public class SysLogininforController extends BaseController<SysLogininfor> {

  @Autowired
  private ISysLogininforService logininforService;

  @RequiresPermissions("monitor:logininfor:list")
  @GetMapping("/list")
  public TableDataInfo list (SysLogininfor logininfor) {
    IPage<SysLogininfor> page = logininforService.selectLogininforPageList(getPage(), logininfor);
    return getDataTable(page);
  }

  @SkipLogParam
  @SkipResponseLog
  @OperatorLog(title = "登录日志", businessType = BusinessType.EXPORT)
  @RequiresPermissions("monitor:logininfor:export")
  @PostMapping("/export")
  public void export (HttpServletResponse response, SysLogininfor logininfor) {
    List<SysLogininfor> list = logininforService.selectLogininforList(logininfor);
    ExcelUtil<SysLogininfor> util = new ExcelUtil<SysLogininfor>(SysLogininfor.class);
    util.exportExcel(response, list, "登录日志");
  }

  @RequiresPermissions("monitor:logininfor:remove")
  @OperatorLog(title = "登录日志", businessType = BusinessType.DELETE)
  @DeleteMapping("/{infoIds}")
  public AjaxResult remove (@PathVariable Long[] infoIds) {
    return toAjax(logininforService.deleteLogininforByIds(infoIds));
  }

  @RequiresPermissions("monitor:logininfor:remove")
  @OperatorLog(title = "登录日志", businessType = BusinessType.CLEAN)
  @DeleteMapping("/clean")
  public AjaxResult clean () {
    logininforService.cleanLogininfor();
    return AjaxResult.success();
  }
}
